package org.sport.dbImplement;

import org.sport.dbInterface.DiscussOperation;
import org.sport.model.entityModel.ActivitytableEntity;
import org.sport.model.entityModel.DiscusstableEntity;
import org.sport.repository.DiscusstableRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Allen on 2017/9/22.
 */
@Service
public class DiscussOpeImp implements DiscussOperation{

    @Autowired
    DiscusstableRepository  discussRepository;


    @Override
    public boolean addOneDis(DiscusstableEntity dis) {
        if(dis != null)
        {
            discussRepository.saveAndFlush(dis);
            return true;
        }
        else
            return false;
    }

    @Override
    public boolean delOneDisById(DiscusstableEntity dis) {
        if(dis != null)
        {
            discussRepository.delete(dis.getId());
            return true;
        }
        else
            return false;
    }

    @Override
    public DiscusstableEntity findOneById(DiscusstableEntity dis) {
        return discussRepository.findOne(dis.getId());
    }

    @Override
    public List<DiscusstableEntity> findOneByUserId(DiscusstableEntity dis) {
        return discussRepository.findDisByUserId(dis.getUsertableByUserId());
    }

    @Override
    public List<DiscusstableEntity> findActDisByActId(ActivitytableEntity activitytableEntity) {
        return discussRepository.findActivityDisByActId(activitytableEntity);
    }

    @Override
    public List<DiscusstableEntity> findFolDisById(DiscusstableEntity followId) {
        return discussRepository.findFollowDisById(followId);
    }

    @Override
    public List<DiscusstableEntity> findAllDis() {
        return discussRepository.findAll();
    }
}
